#include <iostream>
#include <algorithm>
using namespace std;

typedef struct SECTION
{
    int l;
    int r;
    bool operator<(struct SECTION w)
    {
        return l < w.l;
    }
    bool operator>(struct SECTION w)
    {
        return l > w.l;
    }
} section;

const int N = 100010;
const int INF = 0x3f3f3f3f;

int s, t;
int n;
section a[N];
int res = 0;       //可覆盖的区间
bool flat = false; //标记是否可以完全覆盖

int main()
{
    freopen("cin.txt", "r", stdin);
    cin >> s >> t;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i].l >> a[i].r;
    sort(a, a + n); //以左区间为基准排序
    for (int i = 0; i < n;)
    {
        int r = -INF;                     //用来更新s
        for (; i < n && a[i].l <= s; ++i) //在有可能盖过了的前提下，注意，这里是有可能，毕竟区间可能很短
            r = max(r, a[i].r);           //另一端要尽可能的长
        if (r < s)                        //相当于前面都太短了，一个都盖不住
            break;                        //那就没法更新了啊
        else                              //不然
        {
            ++res;      //就是盖住了而且更新成功
            s = r;      //就进行更新
            if (s >= t) //如果盖完了
            {
                flat = true; //就标记成功
                break;       //并且直接返回
            }
        }
    }
    if (flat)
        cout << res;
    else
        cout << -1;
    return 0;
}